<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"  %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'register.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	

  </head>
   <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/statics/css/register.css">
 
  <body>
<div id="div111"><img src="${pageContext.request.contextPath }/statics/images/bei.jpg" /></div>

<div class="Big-div" >
 <font class="title" face="微软雅黑" size="6px;" color="white" >BeidaJadeBird/注册</font><br>
 <font class="title-1" face="微软雅黑" size="2px;" color="white" >已有账号？<a href="login.jsp">登录</a></font>

<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<form action="add"  class="form" method="post">
<input class="a" type="text" placeholder="※电话 ：" id="phone" name="phone"><br><span class="tip user_hint"></span><br><br><br>
<input class="a" type="password" placeholder="※密码 ：" id="pwd" name="pwd"><br><span class="tip pwd_hint"></span><br><br><br>
<input class="a" type="password" placeholder="※再次确认密码 ：" id="pwdt" name="pwdt"><br><span class="tip pwdt_hint"></span><br><br><br>
<input class="a" type="text" placeholder="邮箱 ：" id="email" name="email"><br><span class="tip email_hint"></span><br><br><br>
<select class="sel" name="sel">
<option value=0>请选择</option>
</select >

<select class="selt" name="selt">
<option value=0>请选择</option>
<c:forEach var="values" items="${r}">
<option value=${values.id}>${values.positionname }</option>
</c:forEach>
</select>
<br><input id="b" class="b" type="submit" value="提交"> 
</form>
</div>
  <font face="微软雅黑" size="2px;" color="white" style="position: absolute;bottom: 10px;left:20%;">Copyright @ 2017  北大青鸟本网站只供内部人员浏览，未经同意，不允许转载资料披漏</font>


  <script type="text/javascript" src="${pageContext.request.contextPath}/statics/js/jquery-1.8.3.js"></script>
	<script type="text/javascript">
	
	$(function(){
		

	   
		var password_Boolean = false;
		var varconfirm_Boolean = false;
		var emaile_Boolean = false;
		var Mobile_Boolean = false;
		var a=false;
		var b=false;
		$('#phone').blur(function(){
			  if ((/^1[34578]\d{9}$/).test($("#phone").val())){
			    $('.user_hint').html("✔").css("color","green");
			    Mobile_Boolean = true;
			    $.getJSON("selectRole",{"userPhone":$(this).val()},function(result){
			    	console.log(result);
			    	var str="";
			    	 $.each(result[1],function(i){
			    		// alert(this.departmentname);
			    	 str+= "<option value="+this.id+">"+this.departmentname+"</option>";
			    	 
			    	 });
			    	$(".sel").html(str);
			    	
			    
	    			 
	    			 alert(result[0].p.id);
	    			 $(".sel").val(result[0].ds.id); 
	    			 $(".selt").val(result[0].p.id);
	    			 
	    			 if(result[0].p.id==2){
	    				 alert("该角色禁止注册");
	    				 $("#b").attr("disabled","disabled");
	    				 $("#b").css("background","gray");
	    				 return;
	    			 }else{
	    				 $("#b").attr("disabled",false);
	    				 $("#b").css("background","#1E90FF");
	    				 
	    			 }
	    			 
	 if(result[0].p.id==3){
		 alert("该角色禁止注册");	 
		 $("#b").attr("disabled","disabled");
		 $("#b").css("background","gray");
		 return;   			 
	 }else{
	    				 $("#b").attr("disabled",false);
	    				 $("#b").css("background","#1E90FF");
	    				 
	    			 }
	    			 
	    			 
					  if ($(".sel").val()!=0){
							
						    a = true;
						  }else {
						
						    a = false;
						  }
					
			 if ($(".selt").val()!=0){
					
				    b = true;
				  }else {
				
				    b = false;
				  }
			
		    
	    		 }); 
	    		 
	    	
			   
			    
			    
			    $.getJSON("selectCount",{"userPhone":$(this).val()},function(result){
			    	
				   	 $.each(result,function(i){
		    			
		    	if(result[i]>0){
		    	    $('.user_hint').html("用户已存在").css("color","red");
		    	    Mobile_Boolean = false;
		    	}

						  if ($(".sel").val()!=0){
								
							    a = true;
							  }else {
							
							    a = false;
							  }
						
				 if ($(".selt").val()!=0){
						
					    b = true;
					  }else {
					
					    b = false;
					  }
				
			    
		    		 }); 
		    		 
		    	});
				   
			    
			    
			    
			  }else {
			    $('.user_hint').html("电话格式错误").css("color","red");
			    Mobile_Boolean = false;
			  }
			});
		
		
		$('#pwd').blur(function(){
			  if ((/^[a-z0-9_-]{6,16}$/).test($("#pwd").val())){
			    $('.pwd_hint').html("✔").css("color","green");
			    password_Boolean = true;
			  }else {
			    $('.pwd_hint').html("用户名长度须6-16位且包含数字和字母(不能有特殊字符)！！").css("color","red");
			    password_Boolean = false;
			  }
			});
		

		$('#pwdt').blur(function(){
			  if (($("#pwd").val())==($("#pwdt").val())){
			    $('.pwdt_hint').html("✔").css("color","green");
			    varconfirm_Boolean = true;
			  }else {
			    $('.pwdt_hint').html("两次密码不一致！！").css("color","red");
			    varconfirm_Boolean = false;
			  }
			});
		
		
		
		
		$('#email').blur(function(){
			  if ((/^[a-z\d]+(\.[a-z\d]+)*@([\da-z](-[\da-z])?)+(\.{1,2}[a-z]+)+$/).test($("#email").val())){
				  $('.email_hint').html("<input type='checkbox' name='position' value='1'/>是否邮箱提醒").css("color","green");
				    emaile_Boolean = true;
			  }else {
				  $('.email_hint').html("邮箱格式不正确！！").css("color","red");
				    emaile_Boolean = false;
				
			    
			  }
			});

		
		$('.sel').blur(function(){
			
			  if ($(".sel").val()!=0){
			
			    a = true;
			  }else {
			
			    a = false;
			  }
			});
		
		$('.selt').blur(function(){
	
			  if ($(".selt").val()!=0){
			
			    b = true;
			  }else {
			
			    b = false;
			  }
			});

		
		
		$('.b').click(function(){
	
	
	

			  if( password_Boolean && varconfirm_Boolean  && Mobile_Boolean && a && b == true){
			    
				  
				  
				  alert("注册成功");
			    return true;
			  }
			  else{
			    alert("请完善信息！！");
			    return false;
			  }
			});
		
		
		
		$(".selt").change(function(){
			
			 
			 if($(".selt").get(0).selectedIndex==2){
				 alert("该角色禁止注册");
				 $("#b").attr("disabled","disabled");
				 $("#b").css("background","gray");
				 return;
			 }else{
				 $("#b").attr("disabled",false);
				 $("#b").css("background","#1E90FF");
				 
			 }
			 
if($(".selt").get(0).selectedIndex==3){
 alert("该角色禁止注册");	 
 $("#b").attr("disabled","disabled");
 $("#b").css("background","gray");
 return;   			 
}else{
				 $("#b").attr("disabled",false);
				 $("#b").css("background","#1E90FF");
				 
			 }
			 
		});
		
		
		
		
		
	});
	
	
	
	
	
	</script>
  </body>
</html>
